$(function(){

	$.ajax({
		type: "POST",//方法类型
		url: "/oauthplatform/wel/logData" ,//url
		success: function (result) {
			var logData = result.data.logData;
			var roleList = result.data.roleList;
			var weekDays = result.data.weekDays;
			var seriesArr = new Array();


			for(var i = 0;i<roleList.length;i++){
				var series = new Object();
				series.name = roleList[i].name;
				series.type = 'line';
				series.stack = '总量';
				series.data = new Array(weekDays.length);
				series.areaStyle = new Object();
				for(var j =0;j<weekDays.length;j++){
					var days = weekDays[j];
					series.data[j] = 0;
					for(var l = 0;l<logData.length;l++){
						var log = logData[l];
						if(log.create_time.indexOf(days) >=0 && log.role_name.indexOf(series.name) >=0){
							series.data[j] = log.role_num;
						}
					}
				}
				seriesArr.push(series);
			}
			pieCharts(seriesArr,weekDays);
		},
		error: function (result) {

		}
	});


	getStatisticsData();

	$.ajax({
		type: "POST",//方法类型
		url: "/oauthplatform/wel/mapData",
		success: function (result) {
			mapChart(result.data);
		}
	})

})




function pieCharts(seriesArr,xLinesData){
	//资源分布情况
	var option = {
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'cross',
				label: {
					backgroundColor: '#6a7985'
				}
			}
		},
		grid: {
			left: '3%',
			right: '4%',
			bottom: '8%',
			top: '3%',
			containLabel: true
		},
		xAxis: [
			{
				type: 'category',
				boundaryGap: false,
				data: xLinesData
			}
		],
		yAxis: [
			{
				type: 'value'
			}
		],
		series: seriesArr
	};
	var myChart = echarts.init(document.getElementById('echartsDiv'));
	myChart.setOption(option);

}

//获取首页数据统计信息
function getStatisticsData(){
	$.ajax({
		type: "POST",//方法类型
		url: "http://hnzj.hneduit.com/statistical/dataOverview" ,//url
		success: function (result) {
			$("#courseNum").html(result.courseSum);
			$("#resourceNum").html(parseInt(result.resourceSum) + 100000);
			$("#projectNum").html(result.projectSum);
		},
		error: function (result) {
			$("#courseNum").html(0);
			$("#resourceNum").html(0);
			$("#projectNum").html(0);
		}
	});

}

function mapChart(data){
	$.get('/oauthplatform/static/lib/echarts-4.9/json/henan/henan.json', function (mapJson) {
		//加载地图模块
		echarts.registerMap('hnMap', mapJson);
		//设定需要连线的坐标点

		//拼装地图数据
		var mdata = [];
		for(var i = 0;i<data.length;i++){
			var d = data[i];
			mdata.push({name: d.area_name,value: d.dept_num,user_value:d.user_num});
		}


		var chart = echarts.init(document.getElementById('map-chart-div'));
		var option = {
			tooltip:{
				trigger: 'item',
				triggerOn:'mousemove',
				formatter: function(res){
					var tooltipData = res.data;
					return tooltipData.name + "</br>院校数：" + tooltipData.value+ "</br>用户数：" + tooltipData.user_value;
				}
			},
			visualMap: {
				min: 0,
				max: 50,
				text: ['','院校数(单位：所)'],
				realtime: false,
				calculable: true,
				inRange: {
					color: ['lightskyblue', 'yellow', 'orangered']
				}
			},
			series:[
				{
					type: 'map',
					mapType: 'hnMap',
					data: mdata,
					roam: false,
					label: {
						show: true
					},
					zoom : 1,
					top:'1%',
				}
			]
		}
		chart.setOption(option);
	});
}
